<template>
  <div class="common-head">
    <div class="head-left">
      <i
        @click="toggleMenu"
        :class="$store.state.menu.menuCollapse?'el-icon-s-unfold': 'el-icon-s-fold'" 
        style="cursor:pointer"></i>
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/dashBoard' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item v-for="menu in $store.state.menu.menuNames" :key="menu">
          {{menu}}
        </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="head-right">
      <el-dropdown>
        <div class="user-info">
          <img
            src="https://img2.baidu.com/it/u=3814762419,638738365&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=500"
            alt
            class="avatar"
          />
          <span>小甜甜</span>
        </div>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item>个人中心</el-dropdown-item>
          <el-dropdown-item>推出登录</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
  </div>
</template>

<script>
export default {
  methods: {
    toggleMenu () {
      // 点击切换侧边导航展开和管理
      this.$store.commit('menu/TOGGLE_MENU')
    }
  },
  watch: {
    $route (to) {
      if (to.path === '/dashBoard') {
        // 路由跳转到首页 清除 之前面包屑的导航路径
        this.$store.commit('menu/CLEAR_MENU')
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.common-head {
  display: flex;
  height: 100%;
  justify-content: space-between;
  align-items: center;
  .head-left {
    display: flex;
    align-items: center;
    i {
      color: #333;
      margin-right: 10px;
      font-size: 20px;
    }
  }
  .head-right {
    .user-info {
      font-size: 14px;
      display: flex;
      padding-right: 15px;
      align-items: center;
      cursor: pointer;
      img {
        width: 50px;
        margin-right: 8px;
      }
    }
  }
}
</style>
